<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<br>
<script>
    var socket ;
    if(window.WebSocket){
        socket = new WebSocket("ws://127.0.0.1:8888/websocket");
        socket.onmessage = function (event) {
            var ta  = document.getElementById("responseText");
            ta.value = "" ;
            ta.value = event.data ;
        };
        socket.onopen = function(event){
            alert("打开websocket正常，浏览器支持websocket!");
        };
        socket.onclose = function (event) {
            var ta  = document.getElementById("responseText");
            ta.value = "";
            ta.value = "websocket关闭!";
        };
    }else{
        alert("浏览器不支持websocket协议!");
    }

    function send(message){
        if(!window.WebSocket){
            return;
        }
        if(socket.readyState == WebSocket.OPEN){
            socket.send(message);
        }else{
            alert("websocket链路没有建立成功!");
        }
    }

</script>
<form onsubmit="return false;">
    <input type="text" name="message" value="netty最佳实践!">
    <br>
    <br>
    <input type="button" value="发送websocket请求消息！" onclick="send(this.form.message.value)" >

    <hr color="blue">
    <h3>服务端返回消息</h3>
    <textarea id="responseText" style="width: 500px;height: 300px;"></textarea>
</form>
</body>
</html>